package ai.people.platform.archives.controller;


import ai.people.netmon.framework.domain.archives.request.InformationSearchRequest;
import ai.people.netmon.framework.domain.archives.vo.InformationBehaviorRespListVO;
import ai.people.netmon.framework.domain.archives.vo.InformationDetailRespVO;
import ai.people.netmon.framework.domain.archives.vo.InformationSearchRespListVO;
import ai.people.netmon.framework.domain.archives.vo.InformationViewedOverviewRespVO;
import ai.people.netmon.framework.model.request.PageKeyWordsRequest;
import ai.people.netmon.framework.model.response.PageResponse;
import ai.people.netmon.framework.model.response.Result;
import ai.people.netmon.framework.utils.ResultUtil;
import ai.people.platform.archives.service.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 信息查询接口
 * @author LiGuanNan
 * @date 2022/5/31 下午2:23
 */
@RestController
@RequestMapping("v1/information")
public class InformationController {

    @Autowired
    private InformationSearchService informationSearchService;

    /**
     * 信息检索
     *
     * @param reqParam 请求参数
     * @return {@link Result}<{@link InformationSearchRespListVO}<{@link InformationSearchRespListVO}>>
     */
    @PostMapping("/search")
    public Result<PageResponse<InformationSearchRespListVO>> search(@Validated @RequestBody InformationSearchRequest reqParam) {
        if(StringUtils.isBlank(reqParam.getSearchKeywords())){
            return ResultUtil.success(PageResponse.builderEmpty());
        }
        return ResultUtil.success(informationSearchService.search(reqParam));
    }

    /**
     * 查看详情
     *
     * @param dataSource 数据源类型 FOZA
     * @param dataId     数据标识
     * @return {@link Result}<{@link InformationDetailRespVO}>
     */
    @GetMapping("/detail/{dataSource}/{dataId}")
    public Result<InformationDetailRespVO> detail(@PathVariable(value = "dataSource") String dataSource,
                                                  @PathVariable(value = "dataId") String dataId) {
        return ResultUtil.success(informationSearchService.detail(dataSource, dataId));
    }

    /**
     * 行为列表
     *
     * @param reqParam 请求参数
     * @return {@link Result}<{@link InformationBehaviorRespListVO}>
     */
    @PostMapping("/behavior-history")
    public Result<PageResponse<InformationBehaviorRespListVO>> behaviorHistory(@Validated @RequestBody PageKeyWordsRequest reqParam) {
        return ResultUtil.success(informationSearchService.behaviorHistory(reqParam));
    }

    /**
     * 已查看记录列表
     *
     * @param reqParam 请求参数
     * @return {@link Result}<{@link InformationSearchRespListVO}>
     */
    @PostMapping("/viewed-list")
    public Result<PageResponse<InformationSearchRespListVO>> viewedList(@Validated @RequestBody PageKeyWordsRequest reqParam) {
        return ResultUtil.success(informationSearchService.viewedList(reqParam));
    }

    /**
     * 已查看概览
     *
     * @return {@link Result}<{@link InformationViewedOverviewRespVO}>
     */
    @GetMapping("/viewed-overview")
    public Result<InformationViewedOverviewRespVO> scoreOverview() {
        return ResultUtil.success(informationSearchService.scoreOverview());
    }
}
